﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;
using PBOffice.Models;
public partial class FileManager_Recycle_ : System.Web.UI.Page
{
    //绑定的是模糊查询出的结果

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            List<FileInfo> list = new FileInfoManager().GetAllFileInfoDeleted();
            this.GridView1.DataSource = list;
            this.GridView1.DataBind();
        }
    }

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int fileId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
        new FileInfoManager().DeleteFileInfo(fileId);
        FileInfo file = new FileInfoManager().GetAllFileInfoByFileId(fileId);
        System.IO.Directory.Delete(Server.MapPath(file.FilePath));
        if (new AccFileManager().GetAllAccFileByFileId(fileId).Count != 0)
        {
            new AccFileManager().DeleteAccFile(fileId);
            foreach (AccFile item in new AccFileManager().GetAllAccFileByFileId(fileId))
            {
                System.IO.Directory.Delete(item.AccPath);
            }


        }

    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "chexiao")
        {
            GridViewRow dv = (GridViewRow)(((ImageButton)(e.CommandSource)).Parent.Parent);
            int fileId = Convert.ToInt32(GridView1.DataKeys[dv.RowIndex].Value);
            FileInfo file = new FileInfoManager().GetAllFileInfoByFileId(fileId);
            FileInfo file2 = new FileInfo();
            file2.CreateDate = file.CreateDate;
            file2.FileId = file.FileId;
            file2.FileName = file.FileName;
            file2.FileOwner = file.FileOwner;
            file2.FilePath = file.FilePath;
            file2.FileType = file.FileType;
            file2.IfDelete = 0;
            file2.ParentId = file.ParentId;
            file2.Remark = file.Remark;
            new FileInfoManager().UpdateFileInfo(file2);
            List<FileInfo> list = new FileInfoManager().GetAllFileInfoDeleted();
            this.GridView1.DataSource = list;
            this.GridView1.DataBind();

        }
    }
}